import { NgModule } from '@angular/core';
import { Routes, RouterModule, Route } from '@angular/router';
import { MessageComponent } from './components/message/message.component';
import { WebMessageListComponent } from './components/web-message-list/web-message-list.component';
import { ClientMessageListComponent } from './components/client-message-list/client-message-list.component';
import { MessageTemplateComponent } from './components/message-template/message-template.component';
import { WebMessageSendComponent } from './components/web-message-send/web-message-send.component';
import { ClientMessageSendComponent } from './components/client-message-send/client-message-send.component';
import { MessageTemplateAddComponent } from './components/message-template-add/message-template-add.component';
import { ClientMessageService } from './services/client-message.service';
import { WebMessageService } from './services/web-message.service';
import { WebMessageDetailComponent } from './components/web-message-detail/web-message-detail.component';
import { WebMessageDetailService } from './services/web-message-detail.service';
import { ClientMessageDetailComponent } from './components/client-message-detail/client-message-detail.component';
import { ClientMessageDetailService } from './services/client-message-detail.service';

// 站内信
const webMessageRoute: Route = {
  path: 'web',
  data: { title: '站内信管理' },
  children: [
    { path: '', pathMatch: 'full', redirectTo: 'all' },
    {
      path: 'send',
      component: WebMessageSendComponent,
      data: { title: '新建站内信', hide_nav: true },
    },

    {
      path: ':status',
      component: WebMessageListComponent,
      runGuardsAndResolvers: 'always',
      resolve: { list: WebMessageService },
    },
    {
      path: ':status/detail/:title',
      component: WebMessageDetailComponent,
      resolve: { data: WebMessageDetailService },
      data: { title: '消息详情', hide_nav: true },
    },
  ],
};
// 平台消息
const clientMessageRoute: Route = {
  path: 'client',
  data: { title: '平台消息管理' },
  children: [
    { path: '', pathMatch: 'full', redirectTo: 'all' },
    {
      path: 'send',
      component: ClientMessageSendComponent,
      data: { title: '新建平台消息', hide_nav: true },
    },
    {
      path: ':type',
      component: ClientMessageListComponent,
      runGuardsAndResolvers: 'always',
      resolve: { list: ClientMessageService },
    },
    {
      path: ':type/detail/:title',
      component: ClientMessageDetailComponent,
      resolve: { data: ClientMessageDetailService },
      data: { title: '消息详情', hide_nav: true },
    },
  ],
};
const templateRoute: Route = {
  path: 'template',
  data: { title: '消息模版管理' },
  children: [
    { path: '', component: MessageTemplateComponent },
    {
      path: 'add',
      component: MessageTemplateAddComponent,
      data: { title: '添加模版', hide_nav: true },
    },
  ],
};

const routes: Routes = [
  {
    path: '',
    data: { title: '消息管理' },
    children: [
      { path: '', pathMatch: 'full', redirectTo: 'web' },
      {
        path: '',
        component: MessageComponent,
        children: [webMessageRoute, clientMessageRoute, templateRoute],
      },
    ],
  },
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule],
})
export class MessageRoutingModule {}
